<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    var y = 2021;
    var m = 12;
    var d = 31;

    // 8月19
    // 不需要计算8月的总天数，因为8月还没过完
    // 只需要计算8月之前所有的月份的天数和
    // 1月+2月+3月+4月+5月+6月+7月

    var sum = 0;

    switch(m){
        case 12:
            sum = sum + 30;
        case 11:
            sum = sum + 31;
        case 10:
            sum = sum + 30;
        case 9:
            sum = sum + 31;
        case 8:
            sum = sum + 31;
        case 7:
            sum = sum + 30;
        case 6:
            sum = sum + 31;
        case 5:
            sum = sum + 30;
        case 4:
            sum += 31;
        case 3:
            sum += 28;
        case 2:
            sum += 31;
        case 1:
            sum += d;
    }
    
    console.log(sum);


</script>
</html>